/**
 * @(#)HistoryTodayService.java, 2013-2-11. Copyright 2013 RENREN, Inc. All
 *                               rights reserved. RENREN
 *                               PROPRIETARY/CONFIDENTIAL. Use is subject to
 *                               license terms.
 */
package com.wennimei.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Service;

import com.wennimei.domain.HistoryToday;
import com.wennimei.util.DataUtil;
import com.wennimei.util.FileProcessor;
import com.wennimei.util.FileUtil;

/**
 * @author shichen.feng@renren-inc.com
 */
@Service
public class HistoryTodayService {
    private static final Map<String, List<HistoryToday>> map = new HashMap<String, List<HistoryToday>>();

    @PostConstruct
    void init() {
        FileUtil.processFile(DataUtil.HISTORY_TODAY, new FileProcessor() {

            @Override
            public void process(String line) {
                String[] array = line.split(" ");
                String key = array[0].substring(array[0].length() - 4,
                        array[0].length());
                HistoryToday history = new HistoryToday(array[0], array[1],
                        null);
                List<HistoryToday> list = map.get(key);
                if (null == list)
                    list = new ArrayList<HistoryToday>();

                list.add(history);
                map.put(key, list);
            }
        });
    }

    public List<HistoryToday> get(String date) {
        return map.get(date);
    }
}
